'use client'; import * as React from 'react'; import { Alert, Badge, Button, Card, Collection, Divider, Flex, Heading, Image, Rating, SelectField, StepperField, SwitchField, Text, View, } from '@aws-amplify/ui-react'; import '@aws-amplify/ui-react/styles.css'; import { PAINTINGS } from './paintings'; export default function Home() { const [currentPainting, setCurrentPainting] = React.useState(PAINTINGS[0]); const [image, setImage] = React.useState(PAINTINGS[0].src); const [frame, setFrame] = React.useState(true); const [quantity, setQuantity] = React.useState(1); const [size, setSize] = React.useState(''); const [error, setError] = React.useState(false); const handleAddToCart = () => { if (size === '') { setError(true); return; } alert( `Added to cart!\n${quantity} ${size} "${currentPainting.title}" by ${ currentPainting.artist } with ${frame ? 'a' : 'no'} frame` ); }; return ( {`${currentPainting.title} {(item, index) => ( setImage(item.src)} onMouseLeave={() => setImage(currentPainting.src)} key={index} justifyContent="center" > {`${item.title} setCurrentPainting(item)} borderRadius="5px" padding="3px" marginBottom="1rem" style={{ cursor: 'pointer', ...(currentPainting.src === item.src && { border: '1px solid #e77600', boxShadow: 'rgba(0, 0, 0, 0.35) 0px 3px 8px', }), }} /> )} {currentPainting.title} {currentPainting.bestSeller ? ( Bestseller ) : null} {currentPainting.isNew ? ( New ) : null} {currentPainting.limitedSupply ? ( Limited supply ) : null} {currentPainting.artist} {currentPainting.reviews} reviews Price: {currentPainting.price} {currentPainting.description} {currentPainting.readyForPickup ? ( Ready within 2 hours {' '} for pickup inside the store ) : null} { setFrame(e.target.checked); }} isDisabled={!currentPainting.inStock} /> { e.target.value !== '' && setError(false); setSize(e.target.value); }} hasError={error} errorMessage="Please select a size." isDisabled={!currentPainting.inStock} > {!currentPainting.inStock ? ( Out of stock! ) : null} Qty: ); }